package com.qian.drools;

import com.qian.drools.entity.Customer;
import com.qian.drools.entity.Order;
import com.qian.drools.entity.Person;
import com.qian.drools.entity.School;
import org.kie.api.KieServices;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: QianMo
 * Date: 2021/2/24
 * Time: 10:20
 */
public class Test {
    public static void main(String[] args) {
        System.out.println(">>>>>>>>>>");
        KieServices kss = KieServices.Factory.get();
        KieContainer kcc = kss.getKieClasspathContainer();
        /*StatelessKieSession test = kcc.newStatelessKieSession("test");
        KieCommands commands = kss.getCommands();
        Command command = commands.newFireAllRules();
        test.execute(new Object());*/
        KieSession ks = kcc.newKieSession("session");
        Person person = new Person("张三", 30, "???");
        ks.insert(person);
        int rules = ks.fireAllRules();
        System.out.println(rules);
        ks.dispose();
    }
    @org.junit.Test
    public void test1(){
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test1");
        Customer customer = new Customer();
        customer.setGender("male");
        customer.setAge(10);
        Order order = new Order(customer, 1100);
        test1.setGlobal("cr",customer);
        test1.insert(order);
        test1.insert(customer);
        test1.fireAllRules();
        test1.dispose();
    }
    @org.junit.Test
    public void school(){
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test1");
        School school = new School("散散");
        Person person = new Person("散散", 20, "");
        test1.insert(school);
        test1.insert(person);
        test1.fireAllRules();
        test1.dispose();
    }
    @org.junit.Test
    public void lists(){
        List<String> list = new ArrayList<>();
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test1");
        list.add("一");
        list.add("二");
        list.add("三");
        Person person = new Person("二", 30, "");
        test1.insert(person);
        test1.setGlobal("list",list);
        test1.fireAllRules();
        test1.dispose();
    }
    @org.junit.Test
    public void regs(){
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test1");
        Person person = new Person("张三", 100, "");
        test1.insert(person);
        test1.fireAllRules();
        test1.dispose();
    }
    @org.junit.Test
    public void salience(){
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test2");
        test1.fireAllRules();
        test1.dispose();
    }
    @org.junit.Test
    public void loops(){
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test1");
        Person person = new Person("李四", 30, "");
        test1.insert(person);
        test1.fireAllRules();
        test1.dispose();
    }
    @org.junit.Test
    public void dee(){
        KieServices kss = KieServices.Factory.get();
        KieContainer kc = kss.getKieClasspathContainer();
        KieSession test1 = kc.newKieSession("test1");
        test1.fireAllRules();
        test1.dispose();
    }
}
